package net.microfigure.service.impl;

import net.microfigure.model.AreaInfo;
import net.microfigure.commons.result.Tree;
import net.microfigure.mapper.AreaInfoMapper;
import net.microfigure.service.IAreaInfoService;

import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.baomidou.mybatisplus.service.impl.ServiceImpl;

import java.util.ArrayList;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author 林景锋
 * @since 2018-06-15
 */
@Service
public class AreaInfoServiceImpl extends ServiceImpl<AreaInfoMapper, AreaInfo> implements IAreaInfoService {

	@Autowired
	private AreaInfoMapper areaInfoMapper;
	
	@Override
	public List<Tree> selectTree() {
		List<AreaInfo> areaInfoList = selectTreeGrid();
		List<Tree> trees = new ArrayList<Tree>();
		if(areaInfoList  != null) {
			for(AreaInfo areaInfo : areaInfoList) {
				Tree tree = new Tree();
				tree.setId(areaInfo.getId());
				tree.setText(areaInfo.getAreaName());
				tree.setIconCls(areaInfo.getIcon());
				tree.setPid(areaInfo.getPid());
				trees.add(tree);
			}
		}
		return trees;
	}

	@Override
	public List<AreaInfo> selectTreeGrid() {
		EntityWrapper<AreaInfo> wrapper = new EntityWrapper<AreaInfo>();
		wrapper.orderBy("seq");
		return areaInfoMapper.selectList(wrapper);
	}

	@Override
	public List<Tree> selectTreecode() {
		List<AreaInfo> areaInfoList = selectTreeGrid();
		List<Tree> trees = new ArrayList<Tree>();
		if(areaInfoList  != null) {
			for(AreaInfo areaInfo : areaInfoList) {
				Tree tree = new Tree();
				long code=Long.parseLong(areaInfo.getCode());//把string类型的code转成long放入id
				System.out.println(code);
				tree.setId(code);
				tree.setText(areaInfo.getAreaName());
				tree.setIconCls(areaInfo.getIcon());
				tree.setPid(areaInfo.getPid());
				trees.add(tree);
			}
		}
		return trees;
	}

	@Override
	public String selectcCodeById(String areaNo) {
		// TODO Auto-generated method stub
		return areaInfoMapper.selectcCodeById(areaNo);
	}

	@Override
	public String selectAreaNoById(String id) {
		// TODO Auto-generated method stub
		return areaInfoMapper.selectAreaNoById(id);
	}
	
}
